import { ref } from 'vue'
import { defineStore } from 'pinia'
import { userInfoReq } from '@/api/user'

export const useUserInfoStore = defineStore('user', () => {
  //----全局状态 state
  const role = ref(0)
  const permissionList = ref()
  const permissionBtnList = ref()

  //----- 修改状态的方法-action

  // 获取用户信息--调用获取用户信息接口--存入pnina --所有页面都可以使用
  async function getUserInfo() {
    const r = await userInfoReq()
    //服务器返回的用户信息
    console.log(r.data)
    // 存入全局状态
    role.value = r.data.data.role
    permissionList.value = r.data.data.permissionList
    permissionBtnList.value = r.data.data.permissionBtnList
  }

  return { getUserInfo, role, permissionList, permissionBtnList }
})
